package com.gopay.bis.pab.expay.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.gopay.bis.pab.expay.operation.PabExPayDataSubmit;
import com.gopay.bis.pab.expay.operation.PabExPayParseData;
import com.gopay.common.Result;
import com.gopay.common.domain.bank.BaseMessage;
import com.gopay.common.domain.bank.ExPayBaseMessage;
import com.gopay.common.domain.bank.pab.expay.PabExPayMessage;
import com.gopay.common.exception.GopayException;
import com.gopay.remote.bank.ICertHelper;
import com.gopay.remote.bank.businesses.ExPayService;

/**
 * 
 * @author ShenJun
 *
 */
public class PabExPayBankServiceImpl implements ExPayService {

    private ICertHelper pabExPayCertHelper;
    
    private PabExPayDataSubmit pabExPayDataSubmit;

    private PabExPayParseData pabExPayParseData;

    private static Log logger = LogFactory.getLog(PabExPayBankServiceImpl.class);
    
    private final static String XML_HEADER = "<?xml  version=\"1.0\" encoding=\"utf-8\" ?>\n";

    @Override
    public ExPayBaseMessage sign(BaseMessage baseMsg) throws GopayException {
        return null;
    }

    @Override
    public Result certification(BaseMessage baseMsg) throws GopayException {
    	Result result = new Result();
    	PabExPayMessage msg = (PabExPayMessage) baseMsg;
        String signMsg = (String) pabExPayCertHelper.sign(msg);
        pabExPayDataSubmit.setUrl(baseMsg.getPayUrl());
        Object verRes = pabExPayDataSubmit.submitData(signMsg.toString());
        msg.setSignMessage((String) verRes);
        result = pabExPayParseData.parseResult(verRes, msg);
        result.setModel("ISVERIFY", pabExPayCertHelper.verify(msg));//验签是否成功
        return result;
		
    }

    @Override
    public Result payment(BaseMessage baseMsg) throws GopayException {
    	Result result = new Result();
        PabExPayMessage msg = (PabExPayMessage) baseMsg;
        String signMsg = pabExPayCertHelper.sign(msg);
        pabExPayDataSubmit.setUrl(baseMsg.getPayUrl());
        Object verRes = pabExPayDataSubmit.submitData(signMsg.toString());
        msg.setSignMessage((String) verRes);
        result = pabExPayParseData.parseResult(verRes, msg);
        result.setModel("ISVERIFY", pabExPayCertHelper.verify(msg));//验签是否成功
        return result;
    }

    @Override
    public Result queryOrder(BaseMessage baseMsg) throws GopayException {
    	Result result = new Result();
        PabExPayMessage msg = (PabExPayMessage) baseMsg;
        String signMsg = pabExPayCertHelper.sign(msg);
        pabExPayDataSubmit.setUrl(baseMsg.getQueryUrl());
        Object verRes = pabExPayDataSubmit.submitData(signMsg.toString());
        msg.setSignMessage((String) verRes);
        result = pabExPayParseData.parseResult(verRes, msg);
        result.setModel("ISVERIFY", pabExPayCertHelper.verify(msg));//验签是否成功
        return result;
    }

    @Override
    public ExPayBaseMessage verify(BaseMessage baseMsg) throws GopayException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public ExPayBaseMessage treatyQuery(BaseMessage baseMsg) throws GopayException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public ExPayBaseMessage cancel(BaseMessage baseMsg) throws GopayException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Result refund(BaseMessage baseMsg) throws GopayException {
    	Result result = new Result();
    	PabExPayMessage msg = (PabExPayMessage) baseMsg;
        String signMsg = pabExPayCertHelper.sign(msg);
        pabExPayDataSubmit.setUrl(baseMsg.getPayUrl());
        Object verRes = pabExPayDataSubmit.submitData(signMsg.toString());
        msg.setSignMessage((String) verRes);
        result = pabExPayParseData.parseResult(verRes, msg);
        result.setModel("ISVERIFY", pabExPayCertHelper.verify(msg));//验签是否成功
        return result;
    }

    @Override
    public Object sendSms(BaseMessage baseMsg) throws GopayException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Object checkSms(BaseMessage baseMsg) throws GopayException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Object queryCvn(BaseMessage baseMsg) throws GopayException {
        // TODO Auto-generated method stub
        return null;
    }


    @Override
    public Object signQuery(BaseMessage baseMsg) throws GopayException {
        // TODO Auto-generated method stub
        return null;
    }

	public ICertHelper getPabExPayCertHelper() {
		return pabExPayCertHelper;
	}

	public void setPabExPayCertHelper(ICertHelper pabExPayCertHelper) {
		this.pabExPayCertHelper = pabExPayCertHelper;
	}

	public PabExPayDataSubmit getPabExPayDataSubmit() {
		return pabExPayDataSubmit;
	}

	public void setPabExPayDataSubmit(PabExPayDataSubmit pabExPayDataSubmit) {
		this.pabExPayDataSubmit = pabExPayDataSubmit;
	}

	public PabExPayParseData getPabExPayParseData() {
		return pabExPayParseData;
	}

	public void setPabExPayParseData(PabExPayParseData pabExPayParseData) {
		this.pabExPayParseData = pabExPayParseData;
	}
    
    
    
}
